<%@ page import="com.example.dao.ProductDao" %>
<%@ page import="com.example.util.DBUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    // 检查是否为POST请求
    if (!"POST".equalsIgnoreCase(request.getMethod())) {
        response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }

    request.setCharacterEncoding("UTF-8");
    
    try {
        int productId = Integer.parseInt(request.getParameter("id"));
        
        ProductDao productDao = new ProductDao();
        productDao.deleteProduct(productId);
        
        response.sendRedirect("product_list.jsp?message=商品删除成功");
    } catch (NumberFormatException e) {
        response.sendRedirect("product_list.jsp?error=无效的商品ID");
    } catch (Exception e) {
        response.sendRedirect("product_list.jsp?error=删除商品失败: " + e.getMessage());
    }
%>